package com.joinway.framework.workflow.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.joinway.framework.core.repository.SystemConfigRepository;
import com.joinway.framework.workflow.mobile.bean.AuthCodeView;
import com.joinway.framework.workflow.mobile.bean.VersionView;
import com.joinway.framework.workflow.mobile.constant.MobileWorkflowConstants;

@Service
public class MobileService implements IMobileService {

	@Autowired SystemConfigRepository systemRepository;
	
	@Override
	public int getPriority() {
		return 10;
	}
	
	@Override
	public VersionView getVersion(String platform) throws Exception {
		VersionView view = new VersionView();
		
		String version;
		String url;
		
		if(MobileWorkflowConstants.Platform.Android.equalsIgnoreCase(platform)){
			version = SystemConfigRepository.ClientAndroidVersion;
			url = SystemConfigRepository.ClientAndroidUrl;
		}else{
			version = SystemConfigRepository.ClientIosVersion;
			url = SystemConfigRepository.ClientIosUrl;
		}
		
		view.setVersion(systemRepository.getStringValue(version));
		view.setUrl(systemRepository.getStringValue(url));
		
		return view;
	}

	@Override
	public AuthCodeView sendAuthCode(String phone) throws Exception {
		// TODO
		return new AuthCodeView();
	}

}
